package common;

import java.io.Serializable;
import java.util.List;

import util.Page;

public class BaseBizImpl implements BaseBiz {
	
	private BaseDao dao;
	
	public BaseDao getDao() {
		return dao;
	}

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}

	public <T> boolean save(T t) {
		boolean flag=true;
		try {
			dao.save(t);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public <T> boolean update(T t) {
		boolean flag=true;
		try {
			dao.update(t);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public <T> void executeHql(String hql, Object... values) {
		try {
			dao.executeHql(hql, values);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public <T> boolean delete(T t) {
		boolean flag=true;
		try {
			dao.delete(t);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public <T> T get(Class<T> cls, Serializable ID) {
		T t = null;
		try {
			t = dao.get(cls, ID);
		} catch (Exception e) {
			
		}
		return t;
	}

	public <T> T findOneByHql(String hql, Object... values) {
		T t = null;
		try {
			t = dao.findOneByHql(hql, values);
		} catch (Exception e) {

			e.printStackTrace();
		}
		return t;
	}

	public <T> List<T> findAll(String hql, Object... values) {
		List<T> list=null;
		try {
			list=dao.findAll(hql, values);
		} catch (Exception e) {
			
		}
		return list;
	}

	public Long count(String hql, Object... values) {
		
		return dao.count(hql, values);
	}
	

	public <T> List<T> findAll(String hql, Page pb, Object... values) {
		List<T> list= null;
		try {
			list=dao.findAll(hql, pb.getPageNo(), pb.getPageSize(), values);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}



}
